import Axios from 'axios'
import { Message } from 'element-ui'
let axios = Axios.create({
  baseURL: 'http://192.168.0.20:8842/file',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
axios.interceptors.request.use(config => {
  console.log(config)
  return config
}, error => {
  console.log(error)
})
axios.interceptors.response.use(response => {
  console.log(response)
  if (response.status === 200) {
    return response.data
  } else {
    Message.error(response.data.message)
  }
}, async(error) => {
  console.log(error)
})
export function checkFile(fileName, md5) {
  return axios.get(`/check/file?fileName=${fileName}&md5=${md5}`)
}
export function isUpload(fileMd5) {
  let form = new FormData()
  form.append('filemd5', fileMd5)
  return axios.post('/frag/isUpload', form)
}
export function isFragUpload(index, fragmd5) {
  return axios.post('/frag/isFragUpload', { index, fragmd5 })
}
export function marge(fileName, md5, size) {
  return axios.get(`/marge?fileName=${fileName}&md5=${md5}&size=${size}`)
}
